added samples
[windows-sources.git] / sdk / samples / all in on code / Visual Studio 2010 / CSASPNETBreadcrumbWithQueryString / Item.aspx.cs
blobd22c6580176f302d13a65853b03e327e00195d8a
1 /****************************** Module Header ******************************\
2 * Module Name: Item.aspx.cs
3 * Project: CSASPNETBreadcrumbWithQueryString
4 * Copyright (c) Microsoft Corporation
6 * This page shows a item name. At the same time, this page show the
7 * category name and the item name in the breadcrumb.
8 *
9 * This source is subject to the Microsoft Public License.
10 * See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL.
11 * All other rights reserved.
13 \*****************************************************************************/
15 using System;
16 using System.Web;
18 namespace CSASPNETBreadcrumbWithQueryString
20 public partial class Item : System.Web.UI.Page
22 protected void Page_Load(object sender, EventArgs e)
24 if (!IsPostBack && !string.IsNullOrEmpty(Request.QueryString["name"]))
26 // Show the item name.
27 lbMsg.Text = Request.QueryString["name"];
29 // Handle SiteMapResolve event to dynamically change current SiteMapNode.
30 SiteMap.SiteMapResolve += new SiteMapResolveEventHandler(SiteMap_SiteMapResolve);
34 /// <summary>
35 /// Occurs when the CurrentNode property is accessed.
36 /// </summary>
37 /// <param name="sender">
38 /// The source of the event, an instance of the SiteMapProvider class.
39 /// </param>
40 /// <param name="e">
41 /// A SiteMapResolveEventArgs that contains the event data.
42 /// </param>
43 /// <returns>
44 /// The SiteMapNode that represents the result of the SiteMapResolveEventHandler operation.
45 /// </returns>
46 SiteMapNode SiteMap_SiteMapResolve(object sender, SiteMapResolveEventArgs e)
48 // Only need one execution in one request.
49 SiteMap.SiteMapResolve -= new SiteMapResolveEventHandler(SiteMap_SiteMapResolve);
51 if (SiteMap.CurrentNode != null)
53 // SiteMap.CurrentNode is readonly, so we need to clone one to operate.
54 SiteMapNode currentNode = SiteMap.CurrentNode.Clone(true);
56 currentNode.Title = Request.QueryString["name"];
57 currentNode.ParentNode.Title = Database.GetCategoryByItem(Request.QueryString["name"]);
58 currentNode.ParentNode.Url = "/Category.aspx?name=" + Database.GetCategoryByItem(Request.QueryString["name"]);
60 // Use the changed one in the Breadcrumb.
61 return currentNode;
63 return null;